﻿{include file="/public/header" /}
<div class="content-wraper full">
    <div class="tools-bar">
        <a data-key="add"><i class="fa fa-plus"></i> 新增</a>
        <a data-key="edit"><i class="fa fa-edit"></i> 编辑</a>
        <a data-key="delete"><i class="fa fa-trash"></i> 删除</a>

        <a data-key="lock"><i class="fa fa-lock"></i> 关房</a>        
        <a data-key="unlock"><i class="fa fa-unlock-alt"></i> 恢复空闲</a>
        <a data-key="play"><i class="fa fa-play"></i> 开房</a>

        <a data-key="idle"><i class="fa fa-check-circle"></i> 包厢结账[恢复空闲]</a>
    </div>
    <div class="table_box">
        <table class="table_main" id="datalist"></table>
    </div>
</div>
<script type="text/javascript">
Core.Easyui.FieldColumn = [
    {field:'coperto',title:'最低消费(元)',width:100,align:'center',formatter:function(value,row,index){
        return value || '';
	}},
    {field:'kid',title:'最新订单ID',width:110,align:'center',formatter:function(value,row,index){
        return value || '';
	}},
    {field:'korder',title:'订单房态',width:110,align:'center',formatter:function(value,row,index){
        return row.kid ? '<a href="/korder.info/index/id/'+row.kid+'">'+row.title+'房态</a>' : '';
	}},
    {field:'state',title:'包厢状态',width:100,align:'center',formatter:function(value,row,index){
        return ['<span style="color:gray">关闭</span>','<span style="color:green">空闲</span>','<span style="color:yellow">已预约</span>','<span style="color:red">使用中</span>'][value] || '';
	}},
    {field:'qrcode',title:'二维码',width:100,align:'center',formatter:function(value,row,index){
        return '<a data-key="qrcode" data-id="'+row.id+'"><i class="fa fa-fw fa-qrcode"></i>包厢二维码</a>';
	}},
	{field:'iorder',title:'排序',width:150,align:'center'},
    {field:'sysmsg',title:'系统消息',align:'left'},
];
Core.Easyui.FrozenColumn = [
    {field:'ck',checkbox:true,width:30},
    {field:'id',title:'ID',width:80,align:'center'},
    {field:'btypename',title:'包厢类型',width:100,align:'center'},
    {field:'floorname',title:'楼层',width:100,align:'center'},
    {field:'title',title:'名称',width:320,align:'left',search: true, nowsearch: true, searchtype: 'input'},
];
Core.Easyui.init($("#datalist"), {
    url: "{$_G['_mc_'] ?? ''}/ajax",
    idField: "id",
    fitColumns: false,
    singleSelect : true,
    columns: [Core.Easyui.FieldColumn],
    frozenColumns: [Core.Easyui.FrozenColumn],
    pageSize: 50,
    onDblClickRow: function (index,row){
        Core.Sys.Action('pop',row);
    },
},$(".search_form"));

Core.Sys.Action = function(Tkey,row){
    switch(Tkey){
        case 'add':
            Core.Dialog.open({'title': '新增'+$('div[level="second"] a.active').text(),'width': '500px','height': '320px','url': "{$_G['_mc_'] ?? ''}/edit"});
        break;case 'edit':
            var row = $('#datalist').datagrid('getSelected');if (!row){ Core.Dialog.msg('请选择需要编辑的数据！'); return;}
            Core.Sys.Action('pop',row);
        break;case 'delete':
            var row = $('#datalist').datagrid('getSelected');
            if (!row){Core.Dialog.msg('请选择需要删除的数据！');return;}
            if (row.state!=0){Core.Dialog.msg('非关闭包厢不可删除！');return;}
		    Core.Dialog.confirm({'title':'删除数据','content':'确认要删除该数据吗？','ok':function(cbk){
				$.get("{$_G['_mc_'] ?? ''}/delete/id/"+row.id+"?r="+Math.random(),function(data){
					$("#datalist").datagrid('reload');cbk();
				});
			}})
        break;case 'pop':
            if (!row) return;
            Core.Dialog.open({'title': '编辑'+$('div[level="second"] a.active').text(),'width': '500px','height': '320px','url': "{$_G['_mc_'] ?? ''}/edit/id/"+row.id});
        break;case 'qrcode':
            let id  = row;
            if (!Core.rule('intp',id)) {
                Core.Dialog.msg('请选择包厢');return;
            }
            Core.Dialog.open({'title': '包厢二维码','width': '800px','height': '720px','url': "{$_G['_mc_'] ?? ''}/qr/id/"+id});
        break;case 'lock':
            var row = $('#datalist').datagrid('getSelected');
            if (!row){Core.Dialog.msg('请选择需要关房的数据！');return;}
            if (!row.state){Core.Dialog.msg('包厢已经关房！');return;}
            Core.Dialog.confirm({'title':'包厢关房','content':'确认该包厢要关房吗？','ok':function(cbk){
				$.get("{$_G['_mc_'] ?? ''}/lock/ckey/lock/id/"+row.id+"?r="+Math.random(),function(data){
					$("#datalist").datagrid('reload');cbk();
				});
			}})
        break;case 'unlock':
            var row = $('#datalist').datagrid('getSelected');
            if (!row){Core.Dialog.msg('请选择需要恢复营业的数据！');return;}
            if (row.state!=0){Core.Dialog.msg('非关房包厢无需恢复营业！');return;}
            Core.Dialog.confirm({'title':'恢复营业','content':'确认要该包厢恢复营业吗？','ok':function(cbk){
				$.get("{$_G['_mc_'] ?? ''}/lock/ckey/unlock/id/"+row.id+"?r="+Math.random(),function(data){
					$("#datalist").datagrid('reload');cbk();
				});
			}})
        break;case 'play':
            var row = $('#datalist').datagrid('getSelected');
            if (!row){Core.Dialog.msg('请选择开房的包厢数据！');return;}
            if (row.state!=1){Core.Dialog.msg('非空闲包厢不可使用！');return;}
            Core.Dialog.confirm({'title':'包厢开房','content':'确认使用该包厢吗？','ok':function(cbk){
				$.get("{$_G['_mc_'] ?? ''}/play/id/"+row.id+"?r="+Math.random(),function(data){
					$("#datalist").datagrid('reload');cbk();
				});
			}})
        break;case 'idle':
            var row = $('#datalist').datagrid('getSelected');
            if (!row){Core.Dialog.msg('请选择需要操作的包厢数据！');return;}
            if (row.state != 3){Core.Dialog.msg('非使用中，无需操作！');return;}
            Core.Dialog.confirm({'title':(row.title || '')+'包厢结账','content':'确认该包厢结账恢复空闲吗？','ok':function(cbk){
				$.get("{$_G['_mc_'] ?? ''}/idle/id/"+row.id+"?r="+Math.random(),function(data){
					$("#datalist").datagrid('reload');cbk();
				});
			}})
        break;
    }
    return;
}
/**搜索 */
var Table_Filters = Core.Search.searchArray();
var filterType = Core.Search.typeList();
//var rsourceUrl = "/index/ajax/index"; //搜索字段基础数据
//var regionUrl = "/index/ajax/district/level/"; //城市搜索字段
Core.Search.initFilter("{$_G['_mc_'] ?? ''}/column",null);

$(document).ready(function(){
    $('.tools-bar').find('a[data-key]').on('click',function(){
        var Tkey = $(this).attr('data-key');
        if (!Core.rule('key',Tkey)) return false;
        Core.Sys.Action(Tkey);
    });
    $("body").on("click",'a[data-key="qrcode"]',function(e){
        Core.Sys.Action('qrcode',$(this).attr('data-id'));   
    });
});
</script>
{include file="/public/footer" /}